<?php
/* @var $this ProceduresController */
/* @var $model Procedures */

// $this->breadcrumbs=array(
	// 'Procedures'=>array('index'),
	// 'Manage',
// );

// $this->menu=array(
	// array('label'=>'List Procedures', 'url'=>array('index')),
	// array('label'=>'Create Procedures', 'url'=>array('create')),
// );
$arrayStatus = array(
	0=>'OK',
	1=>'NOT OK',
	2=>'MISSING',
	3=>'NOT USE',
);
$arrayCompare = array(
	0=>'...',
	1=>'Compare (Modified)',
	2=>'Compare (Added)',
);

?>
<div style="overflow: hidden;padding: 30px;position: fixed;right: 0px;top: 20px;background: #282828;color: #fff;">
<form class="form-vertical" id="procedures-form" action="/procedures/admin?Procedures_sort=created.desc" method="post">
	
	
	<div class="row">
		<label for="Procedures_name" class="required">Name <span class="required">*</span></label>		<input size="60" maxlength="200" name="Procedures[name]" id="Procedures_name" type="text">			</div>

	<div class="row">
		
		<label 0="Database - Tables" for="Procedures_table_id">Database</label>
		<?php
		$database = Databases::model()->findAll();
		$dbs = array();


		?>
		<select name="Procedures[database_id]"  id="Procedures_table_id1" >
			<?php
			foreach($database as $key=>$d){
			?>
				<option value="<?php echo outStr($d->id);?>" <?php echo (outStr($model->database_id)==outStr($d->id)) ? "selected" : ""; ?>>
					<?php echo $d->name;?>
				</option>
			<?php
			}
			
			?>
		</select>
		

		
			</div>

	<div class="row">
		<label for="Procedures_status">Status</label>		
		
		<select name="Procedures[status]" id="Procedures_status">
			<?php
			foreach($arrayStatus as $key=>$value){
				echo "<option value='$key'>$value</option>";
			}
			?>

		</select>
		
	</div>	
	<div class="row">
		<label for="Procedures_compare">Compare</label>		
		
		<select name="Procedures[compare]" id="Procedures_status">
			<?php
			foreach($arrayCompare as $key=>$value){
				echo "<option value='$key'>$value</option>";
			}
			?>

		</select>
		
	</div>

	<div class="row buttons">
		<input type="button"  name="yt0" value="Create">	</div>

</form>
</div>
<?php
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$('#procedures-grid').yiiGridView('update', {
		data: $(this).serialize()
	});
	return false;
});
$('.remove_issue').live('click',function(e){
	var issue_id = $(this).attr('issue_id');
	$(this).parent().remove();
	$.get('/procedures/deleteIssue?uuid='+issue_id,function(res){
		
	});
});
$('.form_issue').live('keyup',function(e){
	if(e.keyCode == 13){
		var _this = $(this);
		var oj = $(this).attr('object_id');
		$.post('/procedures/createIssues?object_id='+oj,{content:_this.val()},function(res){
			_this.parent().find('ol').append(res);
		});
		return false;
		
	}

});

$('.form-vertical input[type=button]').live('click',function(e){
	var data = $('.form-vertical').serialize();
	$.post('/procedures/create',data,function(res){
		$('.wide form')[0].reset();
		$('.wide form').trigger('submit');
	});
	console.log(data)
});

");
?>

<h1>Manage Procedures</h1>

<p>
You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>

<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:block">
<?php $this->renderPartial('_search',array(
	'model'=>$model,
)); ?>
</div>

<!-- search-form -->

<?php $this->widget('bootstrap.widgets.TbGridView', array(
	'id'=>'procedures-grid',
	'dataProvider'=>$model->search(),
	// 'filter'=>$model,
	'columns'=>array(
		// 'id',
		array(
			'class' => 'editable.EditableColumn',
			'name'=>'name',
            'value'=>'$data->name',
			'editable' => array(
				'url' => Yii::app()->createUrl('procedures/updateCol'),
				'placement' => 'right',
				'inputclass' => 'span3',
				// 'model' => '$data',
				// 'attribute' => 'outStr($data->id)',
				'params' => array('YII_CSRF_TOKEN' => Yii::app()->request->csrfToken),
			)
		),
		// 'database_id',
		array(            // display 'author.username' using an expression
			'class' => 'editable.EditableColumn',
            'name'=>'database_id',
            'value'=>'$data->database->name',
			'editable' => array(
				'url' => Yii::app()->createUrl('procedures/updateColDB'),
				'placement' => 'right',
				'inputclass' => 'span3',
				'type'      => 'select',
				'source'    => Editable::source(Databases::model()->findAll(), 'id', 'name'),
				'params' => array('YII_CSRF_TOKEN' => Yii::app()->request->csrfToken),
			)
        ),
		array(            // display 'author.username' using an expression
            'name'=>'status',
            'value'=>' $data->database->renderStatus($data->status)',
			'class' => 'editable.EditableColumn',
			'editable' => array(
				'url' => Yii::app()->createUrl('procedures/updateCol'),
				'placement' => 'right',
				'inputclass' => 'span3',
				'type'      => 'select',
				'source'    => $arrayStatus,
				'params' => array('YII_CSRF_TOKEN' => Yii::app()->request->csrfToken),
			)
        ),
		array(            // display 'author.username' using an expression
            'name'=>'issue',
			'type'=>'raw',
            'value'=>array($this,'gridProduct'), 
        ),
		array(            // display 'author.username' using an expression
            'name'=>'Releated',
			'type'=>'raw',
            'value'=>array($this,'gridRelations'), 
        ),
		array(            // display 'author.username' using an expression
            'name'=>'compare',
            'value'=>' $data->renderCompare($data->compare)',
			'class' => 'editable.EditableColumn',
			'editable' => array(
				'url' => Yii::app()->createUrl('procedures/updateCol'),
				'placement' => 'right',
				'inputclass' => 'span3',
				'type'      => 'select',
				'source'    => $arrayCompare,
				'params' => array('YII_CSRF_TOKEN' => Yii::app()->request->csrfToken),
			)
        ),
		array(            // display 'author.username' using an expression
            'name'=>'created',
            'value'=>' date("Y-m-d H:s:i",$data->created)',
        ),
		array(
			'class'=>'CButtonColumn',
			'template'=>'{update}{delete}',
			'buttons'=>array
			(
				'update' => array
				(
					'label'=>'edit',
					'type'=>'raw',
					'url'=>'Yii::app()->createUrl("procedures/update",array("uuid"=>outStr($data->id)))',
				),
				'delete' => array
				(
					'label'=>'Delete',
					'type'=>'raw',
					'url'=>'Yii::app()->createUrl("procedures/delete",array("uuid"=>outStr($data->id)))',
				),
			),
		),
	),
)); ?>
